package com.itheima.design.mode.observer.service;

import com.itheima.design.mode.observer.event.EventManager;
import com.itheima.design.mode.observer.listener.MQEventListener;
import com.itheima.design.mode.observer.listener.MessageEventListener;

public abstract class LotteryService {


    private EventManager eventManager;

    public LotteryService() {
        eventManager = new EventManager(EventManager.EventType.MQ, EventManager.EventType.Message);
        eventManager.subscribe(EventManager.EventType.MQ,new MQEventListener());
        eventManager.subscribe(EventManager.EventType.Message,new MessageEventListener());
    }

    public LotteryResult draw(String uId){
        LotteryResult result = doDraw(uId);
        eventManager.notify(EventManager.EventType.MQ,result);
        eventManager.notify(EventManager.EventType.Message,result);
        return result;
    }
    protected abstract LotteryResult doDraw(String uId);
}
